@layout("/common/_container.html"){
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row row-lg">

                <div class="col-sm-5" id="finance2" class="active ">
                    <table border="1" id="order_message">
                        <tr>
                            <td class="td_headline tdbgc1">客户</td>
                            <td id="customerName"></td>
                            <td class="td_headline tdbgc1">销售日期</td>
                            <td id="saleDate"></td>
                        </tr>
                        <!--<tr>-->
                            <!--<td class="td_headline tdbgc1">开单门店</td>-->
                            <!--<td id="openBillStore"></td>-->
                            <!--<td class="td_headline tdbgc1">库区</td>-->
                            <!--<td id="lib"></td>-->
                        <!--</tr>-->
                        <tr>
                            <td class="td_headline tdbgc1">付款方式</td>
                            <td id="pMethod"></td>
                            <td class="td_headline tdbgc1">付款金额</td>
                            <td id="amount"></td>
                        </tr>
                        <tr>
                            <td class="td_headline tdbgc1">收货人</td>
                            <td id="tMan"></td>
                            <td class="td_headline tdbgc1">收货地址</td>
                            <td id="deliveryAddress"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-sm-3" id="finance2" class="active ">
                    <table border="1" id="order_message">
                        <tr>

                            <td class="td_headline tdbgc2">结算方式</td>
                            <td id="payMode"></td>
                        </tr>
                        <tr>
                            <td class="td_headline tdbgc2">交款人</td>
                            <td id="payer"></td>
                        </tr>
                        <tr>
                            <td class="td_headline tdbgc2">收款人</td>
                            <td id="payee"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-sm-3" id="finance2" class="active ">
                    <table border="1" id="order_message">
                        <tr>
                            <td class="td_headline tdbgc3">出库时间</td>
                            <td id="outStoreTime"></td>
                        </tr>
                        <tr>
                            <td class="td_headline tdbgc3">送货人</td>
                            <td id="outStorePer"></td>
                        </tr>
                        <tr>
                            <td class="td_headline tdbgc3">备注</td>
                            <td id="checkNode"></td>
                        </tr>
                    </table>
                </div>
                <!--财务-->
                <div class="col-sm-1" id="finance" class="active">
                    <!--<div class="btn btn-primary" onclick="ssfs()">导 出</div>-->
                    <div class="btn btn-primary" onclick="print()">打 印</div>
                </div>
                <!--订单部分-->
                <div class="col-sm-12">
                    <!-- Example Pagination -->
                    <div class="tab_underlin" style='border:1px solid #e4eaec;margin-bottom:0px;border-bottom:none;line-height: 40px;height:40px;background-color:#f9f9f9;'>
                        <ul style="float:left;margin-bottom: 0px;">
                            <li>销售单号：<span id="saleNo"></span></li>
                            <li style="margin-left:20px">电商单号：<span id="ecNo"></span></li>
                        </ul>
                    </div>
                    <!-- End Example Pagination -->
                </div>
                <div style="clear:both;"></div>
                <div class="col-sm-12">
                    <!-- Example Pagination -->
                    <div class="example-wrap"  id="lodop_print">
                        <table id="table" data-mobile-responsive="true" data-striped="true" >
                        </table>
                    </div>
                </div>
                <!-- End Example Pagination -->
            </div>
            <!--汇总部分-->
            <div>
                <!-- Example Pagination -->
                <div class="tab_underlin">
                    <ul>
                        <li >退货金额：<span id="tuihuoAmount"></span></li>
                        <li >退红包金额：<span id="redPackAmount"></span></li>
                        <li >运费：<span id="tCost"></span></li>
                        <li >总金额：<span id="amount2"></span></li>
                        <li>折后金额：<span id="actualAmount"></span></li>
                        <li>已优惠：<span id="discountAmount"></span></li>
                    </ul>
                </div>
                <!-- End Example Pagination -->
            </div>
        </div>
        <!--异常类型流程-->
        <div class="col-sm-12" style="height:500px;" id="problem_area"></div>
    </div>
</div>
<!-- End Panel Other -->
</div>
<!-- Peity -->
<script>
    // 获取url中参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
    // $(function(){
    //
    // })
    function print(){
//  	  	            上 左 宽 高
        var LODOP; //声明为全局变量
//			                获取表格信息
        var id=getUrlParam('id');
        // var detailsFlag=getUrlParam('detailsFlag');
        $.ajax({
            url: "/cancelOrder/detail/"+id,
            type:"get",
            dataType: 'json',
            success:function(data){
                LODOP=getLodop();
                // LODOP.PRINT_INIT("银燕公司宽带收费明细");
                LODOP.SET_PRINT_STYLE("FontSize",11)
                // LODOP.SET_PRINT_PAGESIZE(1, 0, 0,80);
                LODOP.ADD_PRINT_TEXT(30, 280, 500, 50, "津小超（销售明细）")
                LODOP.SET_PRINT_STYLEA(1, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(1, "FontSize",16);
                LODOP.SET_PRINT_STYLEA(1, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(70,50,360,20,"客户："+data.customerName);
                LODOP.ADD_PRINT_TEXT(70,365,360,20,"销售日期："+data.saleDate);
                LODOP.ADD_PRINT_TEXT(100,50,360,20,"收货人："+data.tMan);
                // LODOP.ADD_PRINT_TEXT(100,365,360,20,"开单门店："+data.openBillStore);
                LODOP.ADD_PRINT_TEXT(130,50,360,20,"付款方式："+data.payType);
                LODOP.ADD_PRINT_TEXT(130,365,360,20,"付款金额："+data.actualAmount);
                LODOP.ADD_PRINT_TEXT(100,365,360,20,"单号："+data.saleNo);
                LODOP.ADD_PRINT_TEXT(160,50,600,20,"收货地址："+data.deliveryAddress);
                LODOP.ADD_PRINT_TEXT(190,50,600,20,"备注："+data.checkNode);
                var tHtml
                var tHtml
                tHtml += " <table border='1' id='tableall' style='font-size:13px; border-collapse:collapse;border:1px solid black; width:100%' bordercolor='#000000'>";
                tHtml += " <tr style=\"font-size:13px; text-align:center; font-weight:bold;\" > ";
                tHtml += " <td style='width:2.5%'>齐</td>";
                tHtml += " <td style='width:2.5%'>欠</td>";
                tHtml += " <td style='width:30%'>商品名称</td>";
                tHtml += " <td style='width:6%'>规格</td>";
                tHtml += " <td style='width:5%'>数量</td>";
                tHtml += " <td style='width:15%'>条形码</td>";
                tHtml += " <td style='width:5%'>单位</td>";
                tHtml += " <td style='7%'>单位说明</td>";
                tHtml += " <td style='7%'>单价</td>";
                tHtml += " <td style='7%'>金额</td>";
                // tHtml += " <td>库位</td>";
                tHtml += " </tr> ";
                var  pagenum
                pagenum =parseInt((data.orderItemList.length/28).toString().split("."))+1;
                console.log(data)
                for(var j=0;j<pagenum;j++){
                    var tHtml2=''
                    for(var i=j*28;(i<data.orderItemList.length)&&(i<(j*28+28));i++){
                        tHtml2 += " <tr style=\"font-size:13px; text-align:center;height:30px\"> ";
                        tHtml2 += " <td style='width:2.5%'></td>";
                        tHtml2 += " <td style='width:2.5%'></td>";
                        tHtml2 += " <td style='width:30%'>" + data.orderItemList[i].productName+ "</td>";
                        tHtml2 += " <td style='width:6%'>" + data.orderItemList[i].model+"</td>";
                        tHtml2 += " <td style='width:5%'>" + data.orderItemList[i].amount+"</td>";
                        tHtml2 += " <td style='width:15%'>" + data.orderItemList[i].sn+"</td>";
                        tHtml2 += " <td style='width:5%'>" + data.orderItemList[i].unit+"</td>";
                        tHtml2 += " <td style='7%'>1"+data.orderItemList[i].unit+"=" + data.orderItemList[i].unitE/data.orderItemList[i].amount+"件</td>";//单位说明
                        tHtml2 += " <td style='7%'>" + data.orderItemList[i].salesPrice+"</td>";
                        tHtml2 += " <td style='7%'>" + data.orderItemList[i].money+"</td>";
                        // tHtml2 += " <td>" + data.orderItemList[i].reArea+"</td>";
                        tHtml2 += " </tr>";

                    }
                    var tHtml3='';
                    tHtml3 += " <tr style=\"font-size:13px; text-align:center;height:30px\">";
                    tHtml3 += " <td style='width:2.5%'></td>";
                    tHtml3 += " <td style='width:2.5%'></td>";
                    tHtml3 += " <td >合计：" + data.totalAmount+"</td>";
                    tHtml3 += " </tr>";
                    SHtml=tHtml+tHtml2+tHtml3+"</table>"
                    if(j!=0){
                        LODOP.NewPage();
                        LODOP.ADD_PRINT_TABLE(70,0,"100%","100%",SHtml);
                    }else{
                        LODOP.ADD_PRINT_TABLE(220,0,"100%","100%",SHtml);
                    }
                }
                tHtml +="</table> ";
                LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
                LODOP.ADD_PRINT_HTM(1,600,300,50,"总页号：<font color='#0000ff' format='ChineseNum'><span tdata='pageNO'>第##页</span>/<span tdata='pageCount'>共##页</span></font>");
                LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                LODOP.SET_PRINT_STYLEA(0,"Horient",1);
                LODOP.PREVIEW();
            },
            error:function(e){
                console.log(e)
            }
        });
    }
    function abnormal(list){
        console.log(list)
        for(var i=0;i<list.length;i++){
            // 减红包异常
            if(list[i].exType==1){
              var hongbao=''
                hongbao+='<div><h1 class="extypestl">'+list[i].exOrderInfo+'</h1>'
                for(var k=0;k<list[i].exOrderExamList.length;k++){
                    console.log(list[i].exOrderExamList[k].createDeptName)
                    hongbao+='<div class="model">'
                    hongbao+='<h3>审核部门:</h3> <span>'+list[i].exOrderExamList[k].createDeptName+'</span><br>'
                    hongbao+='<h3>审核人员:</h3> <span>'+list[i].exOrderExamList[k].operator+'</span><br>'
                    hongbao+='<h3>审核日期:</h3> <span>'+list[i].exOrderExamList[k].operateTime+'</span><br>'
                    hongbao+='<h3>审核意见:</h3> <span>'+list[i].exOrderExamList[k].opinion+'</span>'
                    hongbao+='</div>'
                    if(k+1<list[i].exOrderExamList.length){
                        hongbao+='<img class="jian2" src="${ctxPath}/static/images/jian2.png" alt="">'
                    }
                }
                    hongbao+='<div style="margin-top:20px;clear:both"></div></div>'
                    $('#problem_area').append(hongbao)
            }else if(list[i].exType==2){
                var product=JSON.parse(list[i].deleteOrderItems)
                console.log(product)
                // 退单品
                var danpin=''
                danpin+='<div><h1 class="extypestl">退单品</h1>'
                danpin+='<div class="col-sm-12" id="finance3" class="active" style="padding-left:0px">'
                danpin+='<table border="1" id="order_message3"><tr>'
                danpin+='<td class="td_headline tdbgc1">商品名称</td>'
                danpin+='<td class="td_headline tdbgc1">条形码</td>'
                danpin+='<td class="td_headline tdbgc1">单位</td>'
                danpin+='<td class="td_headline tdbgc1">件</td>'
                danpin+='<td class="td_headline tdbgc1">数量</td>'
                danpin+='<td class="td_headline tdbgc1">待退货数量</td>'
                danpin+='<td class="td_headline tdbgc1">退货数量</td>'
                danpin+='<td class="td_headline tdbgc1">销售价</td>'
                danpin+='<td class="td_headline tdbgc1">折后价</td>'
                danpin+='<td class="td_headline tdbgc1">金额</td>'
                danpin+='<td class="td_headline tdbgc1">规格/型号</td></tr>'
                for(var j=0;j<product.length;j++){
                    danpin+='<tr style="background-color:#ffffff"><td>'+product[j].orderItem.productName+'</td>'
                    danpin+='<td>'+product[j].orderItem.sn+'</td>'
                    danpin+='<td>'+product[j].orderItem.unit+'</td>'
                    danpin+='<td>'+product[j].orderItem.unitE/product[j].orderItem.amount+'</td>'
                    danpin+='<td>'+product[j].orderItem.amount+'</td>'
                    danpin+='<td>'+product[j].orderItem.forReturnNum+'</td>'
                    danpin+='<td>'+product[j].orderItem.returnNum+'</td>'
                    danpin+='<td>'+product[j].orderItem.salesPrice+'</td>'
                    danpin+='<td>'+product[j].orderItem.disPrice+'</td>'
                    danpin+='<td>'+product[j].orderItem.money+'</td>'
                    danpin+='<td>'+product[j].orderItem.model+'</td></tr>'
                }
                danpin+='</table></div>'
                for(var k=0;k<list[i].exOrderExamList.length;k++){
                    console.log(list[i].exOrderExamList[k].createDeptName)
                    danpin+='<div class="model">'
                    danpin+='<h3>审核部门:</h3> <span>'+list[i].exOrderExamList[k].createDeptName+'</span><br>'
                    danpin+='<h3>审核人员:</h3> <span>'+list[i].exOrderExamList[k].operator+'</span><br>'
                    danpin+='<h3>审核日期:</h3> <span>'+list[i].exOrderExamList[k].operateTime+'</span><br>'
                    danpin+='<h3>审核意见:</h3> <span>'+list[i].exOrderExamList[k].opinion+'</span>'
                    danpin+='</div>'
                    if(k+1<list[i].exOrderExamList.length){
                        danpin+='<img class="jian2" src="${ctxPath}/static/images/jian2.png" alt="">'
                    }
                }
                danpin+='<div style="margin-top:20px;clear:both"></div></div>'
                $('#problem_area').append(danpin)
            }else{
                var tuidan=''
                if(list[i].exType==3){
                    tuidan+='<div><h1 class="extypestl">退货：商家拒收</h1>'
                }else{
                    tuidan+='<div><h1 class="extypestl">退货：商家申请退单</h1>'
                }
                for(var k=0;k<list[i].exOrderExamList.length;k++){
                    console.log(list[i].exOrderExamList[k].createDeptName)
                    tuidan+='<div class="model">'
                    tuidan+='<h3>审核部门:</h3> <span>'+list[i].exOrderExamList[k].createDeptName+'</span><br>'
                    tuidan+='<h3>审核人员:</h3> <span>'+list[i].exOrderExamList[k].operator+'</span><br>'
                    tuidan+='<h3>审核日期:</h3> <span>'+list[i].exOrderExamList[k].operateTime+'</span><br>'
                    tuidan+='<h3>审核意见:</h3> <span>'+list[i].exOrderExamList[k].opinion+'</span>'
                    tuidan+='</div>'
                    if(k+1<list[i].exOrderExamList.length){
                        tuidan+='<img class="jian2" src="${ctxPath}/static/images/jian2.png" alt="">'
                    }
                }
                tuidan+='<div style="margin-top:20px;clear:both"></div></div>'
                $('#problem_area').append(tuidan)
            }
        }
    }
    $('#table').bootstrapTable({
        // url:"js/demo/bootstrap_table_test3.json",
        ajax:function(request){
            var id=getUrlParam('id');
            $.ajax({
                type: "get",
                dataType: "json",
                url: "/cancelOrder/detail/"+id,
                success: function (data) {
                    // console.log(data.exOrderVoList)
                    abnormal(data.exOrderVoList)
                    if(data.amount){
                        $('#amount').html(data.amount)
                    }else{
                        $('#amount').html('— — —')
                    }
                    if(data.amount){
                        $('#amount2').html(data.amount)
                    }else{
                        $('#amount2').html('— — —')
                    }
                    if(data.customerName){
                        $('#customerName').html(data.customerName)
                    }else{
                        $('#customerName').html('— — —')
                    }
                    if(data.deliveryAddress){
                        $('#deliveryAddress').html(data.deliveryAddress)
                    }else{
                        $('#deliveryAddress').html('— — —')
                    }
                    if(data.saleDate){
                        $('#saleDate').html(data.saleDate)
                    }else{
                        $('#saleDate').html('— — —')
                    }
                    if(data.openBillStore){
                        $('#openBillStore').html(data.openBillStore)
                    }else{
                        $('#openBillStore').html('— — —')
                    }
                    if(data.lib){
                        $('#lib').html(data.lib)
                    }else{
                        $('#lib').html('— — —')
                    }
                    if(data.pMethod){
                        $('#pMethod').html(data.payType)
                    }else{
                        $('#pMethod').html('— — —')
                    }
                    //退红包金额、运费
                    $('#tCost').html(data.tCost)
                    if(data.redPackAmount){
                        $('#redPackAmount').html(data.redPackAmount)
                    }else{
                        $('#redPackAmount').html('— — —')
                    }
                    //收货人
                    if(data.tMan){
                        $('#tMan').html(data.tMan)
                    }else{
                        $('#tMan').html('— — —')
                    }
                    if(data.outStoreTime){
                        $('#outStoreTime').html(data.outStoreTime)
                    }else{
                        $('#outStoreTime').html('— — —')
                    }
                    if(data.outStorePer){
                        $('#outStorePer').html(data.outStorePer)
                    }else{
                        $('#outStorePer').html('— — —')
                    }
                    var payModeInfo="";
                    if(data.payMode){
                        var payMode = JSON.parse(data.payMode);
                        for ( var i = 0; i <payMode.length; i++){
                            payModeInfo = payModeInfo+payMode[i].payType+":"+payMode[i].amoun+"元"+"   ";
                        }
                    }
                    if(payModeInfo){
                        $('#payMode').html(payModeInfo)//结算方式
                    }else{
                        $('#payMode').html('— — —')//结算方式
                    }
                    if(data.payer){
                        $('#payer').html(data.payer)//结算方式
                    }else {
                        $('#payer').html('— — —')//结算方式
                    }
                    if(data.payee){
                        $('#payee').html(data.payee)//结算方式
                    }else {
                        $('#payee').html('— — —')//结算方式
                    }
                    if(data.actualAmount){
                        $('#actualAmount').html(data.actualAmount)//结算方式
                    }else {
                        $('#actualAmount').html('— — —')//结算方式
                    }
                    if(data.discountAmount){
                        $('#discountAmount').html(data.discountAmount)//结算方式
                    }else {
                        $('#discountAmount').html('— — —')//结算方式
                    }
                    if(data.saleNo){
                        $('#saleNo').html(data.saleNo)//结算方式
                    }else {
                        $('#saleNo').html('— — —')//结算方式
                    }
                    if(data.ecNo){
                        $('#ecNo').html(data.ecNo)//结算方式
                    }else {
                        $('#ecNo').html('— — —')//结算方式
                    }
                    if(data.checkNode){
                        $('#checkNode').html(data.checkNode)//结算方式
                    }else {
                        $('#checkNode').html('— — —')//结算方式
                    }
                    if(data.refundMoney){
                        $('#tuihuoAmount').html(data.refundMoney)//结算方式
                    }else {
                        $('#tuihuoAmount').html('— — —')//结算方式
                    }
                    request.success({
                        row:data.orderItemList
                    });
                    $('#table').bootstrapTable('load', data.orderItemList);
                },
                error: function (e) {
                    swal({
                        title: "提示",
                        text: "请求服务器出错",
                        type: "error"
                    });
                }

            });
        },
        cache: false, // 设置为 false 禁用 AJAX 数据缓存， 默认为true
        striped: true,  //表格显示条纹，默认为false
        toggle:"table",
        height:530, //表格高度
        columns: [{
            field: 'productName',
            align: 'center',
            title: '商品名称'
        }, {
            field: 'sn',
            align: 'center',
            title: '条形码'
        }, {
            field: 'unit',
            align: 'center',
            title: '单位'
        }, {
            field: 'jian',
            align: 'center',
            title: '件',
            formatter: function (value, row, index) {
                var x=row.unitE/row.amount
                return x
            }
        }, {
            field: 'amount',
            align: 'center',
            title: '数量'
        }, {
            field: 'forReturnNum',
            align: 'center',
            title: '待退货数量'
        }, {
            field: 'returnNum',
            align: 'center',
            title: '退货数量'
        }, {
            field: 'noValency',
            align: 'center',
            title: '正常价'
        }, {
            field: 'salesPrice',
            align: 'center',
            title: '销售价'
        },{
            field: 'disPrice',
            align: 'center',
            title: '折后价'
        },{
            field: 'money',
            align: 'center',
            title: '金额'
        },{
            field: 'model',
            align: 'center',
            title: '规格/型号'
        },{
            field: 'brand',
            align: 'center',
            title: '品牌'
        },{
            field: 'reArea',
            align: 'center',
            title: '产地'
        }]
    });
</script>
@}
